"Javascript is not Java"
JavaScript is a scripting language that enables us to create dynamic content, control media objects, and more.
Computers usually deal with a lot of data, 30 billion bytes just in working memory and even more for hard disk, to handle these Javascript splits them into chunks called values.
Javascript uses 64 bits to store a single number value, which means it can represent 264 numbers that sum up to more than 18 quintillions. The actual maximum whole number that can be stored is more in the range of 9 quadrillions. Fractional numbers are written in decimal form.
For extraordinarily big or small numbers, we can also use the scientific exponent format represented by e followed by the exponent of the number.
example: 3.997e6 = 3.997 x 106
Operators that require two values to give a valid result are called binary operators.
★ Modulo is used to find the remainder.
example: x%y gives the remainder after dividing x by y.
★ ">" and "<" can be applied to numbers, strings, and non-alphabetic characters. Comparison happens from left to right.
Gives the type of value.
example:
typeof(5) -> integer
typeof("word") -> string
★ Minus (-) is both binary and unary operator.
example:
-8: used as a unary operator
8-2: used as a binary operator
and, or, not are logical operators which reason the boolean.
It is a unary operator. It flips the value.
example:
! true -> false
It is a binary operator. It gives result true only when both values are true.When the value on the left converts to false it returns the left value else it will return the value to the right.
It is a binary operator. It gives the result as true when either of the value is true.This will give the value of left when the left value is true.If the left value is not true, then only it will check the right value and give the result.
It is the only ternary operator, i.e. it operates on 3 values.
example:
true?3:4 = 3
When multiple operators of the same precedence occur next to one another, precedence is decided as per the order of appearance from left to right.
We can also add parenthesis which decides precedence.
Javascript represents individual characters using the 16 bits format, but Unicode includes twice as many characters, therefore elements like emojis can take up to two character positions.
The backtick notation(also called template literals) can be used to embed other values, for example:
`twice of 55 is $(55 * 2)`
When we write something inside ${}, the result will be calculated and converted into a string and replace the ${} part of the string.
the above statement would result in "twice of 55 is 110".
We can indicate strings in javascript using single quotes (' '), double quotes (" "), or backticks (` `).
\ - Escaping a character
\n - newline
\t - tab space
We can concatenate two strings by using the "+" operator.
In strings, upper case has lower precedence than lower case.
Boolean has two values, true and false Zero, NaN, and "" (empty string) are false for boolean
true || x gives true
false && x gives false
These values are used to denote the absence of meaningful value, even though they are themselves values and carry no information.
When operators are used with the wrong type of value, Javascript will convert them to the type it needs by default, however the result of such operations may not be desired or expected, this is called type coercion.
However to avoid type coercion we use the operator === and !== to ensure that the value and type are checked.
We learned the 4 types of values in Javascript: numbers, strings, booleans, and undefined values We can combine and transform these values with operators.